<ui:composition template="/xhtml/templates/main.xhtml" 
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
    xmlns:c="http://java.sun.com/jstl/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.prime.com.tr/ui"
	xmlns:cmm="http://alvsanand.appspot.com/common/facelets/tags">
		
		<ui:param name="pageTitle" value="#{bundle_admin['admin.article.title']}" />
		<ui:param name="contentHeader" value="#{bundle_admin['admin.article.header']}" />
		
		<ui:define name="content">
			<ui:decorate template="/xhtml/templates/content.xhtml">
				<!-- header content here  -->
				<ui:define name="pageName">
	                #{contentHeader}
	            </ui:define>
	
				<!-- insert content here -->
				<ui:define name="pageContent">
					<f:view contentType="text/html">
						<h:form prependId="false">
							<p:dataTable value="#{articleBean.lazyModel}" var="article" dynamic="true" lazy="true" paginator="true" rows="10"
							 paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"  
							 rowsPerPageTemplate="5,10,15" paginatorPosition="bottom">
								<p:column>
				            		<h:selectBooleanCheckbox value="#{articleBean.selectedArticles[article.idArticle]}"/>
								</p:column>
								<p:column>
				            		<f:facet name="header">
								    	<h:outputText value="#{bundle_admin['admin.article.param.name']}" />
								  	</f:facet>
					                <h:outputText value="#{article.name}"/>
								</p:column>
								<p:column>
				            		<f:facet name="header">
								    	<h:outputText value="#{bundle_admin['admin.article.param.title']}" />
								  	</f:facet>
					                <h:outputText value="#{article.title}"/>
								</p:column>
								<p:column>
				            		<f:facet name="header">
								    	<h:outputText value="#{bundle_admin['admin.article.param.date']}" />
								  	</f:facet>
					                <h:outputText value="#{article.date}">
					                	<f:convertDateTime pattern="dd/MM/yyyy HH:mm:ss" />	
					                </h:outputText>
								</p:column>
								<p:column>
				            		<f:facet name="header">
								    	<h:outputText value="#{bundle_admin['admin.article.param.modifiedDate']}" />
								  	</f:facet>
					                <h:outputText value="#{article.modifiedDate}">
					                	<f:convertDateTime pattern="dd/MM/yyyy HH:mm:ss" />	
					                </h:outputText>
								</p:column>
								<p:column>
				            		<f:facet name="header">
								    	<h:outputText value="#{bundle_admin['admin.article.param.state']}" />
								  	</f:facet>
								  	<h:outputText value="#{bundle_admin[cmm:replace('admin.article.state.XXX.text','XXX', article.state)]}"/>
								</p:column>
								<p:column>
   									<p:commandLink ajax="false" action="#{articleBean.deleteArticle}" value="#{bundle_admin['admin.delete']}">
   										<f:setPropertyActionListener target="#{articleBean.idArticle}" value="#{article.idArticle}" />      										
   									</p:commandLink>
     								<p:spacer width="20"/>
									<p:commandLink ajax="false" action="#{articleBean.editArticle}" value="#{bundle_admin['admin.edit']}">
   										<f:setPropertyActionListener target="#{articleBean.idArticle}" value="#{article.idArticle}" />      										
   									</p:commandLink>
								</p:column>
					    	</p:dataTable>
					    	
					    	<div class="extraContent">					    	
						    	<p:commandButton id="newArticleBtn" ajax="false" action="#{articleBean.newArticle}" value="#{bundle_admin['admin.create']}"/>	
						    	<p:spacer width="20"/>
						    	<p:commandButton id="desactivateStateArticlesBtn" ajax="false" action="#{articleBean.updateStateArticles}" value="#{bundle_admin['admin.article.disable']}">
									<f:setPropertyActionListener target="#{articleBean.state}" value="0" />										
								</p:commandButton>
						    	<p:spacer width="20"/>
						    	<p:commandButton id="activateStateArticlesBtn" ajax="false" action="#{articleBean.updateStateArticles}" value="#{bundle_admin['admin.article.enable']}">
									<f:setPropertyActionListener target="#{articleBean.state}" value="1" />
								</p:commandButton>
							</div>
						</h:form>
						<h:form id="fileUploadForm">	
							<div class="extraContent">
								<h:panelGrid columns="2">
									<p:fileUpload widgetVar="fileUpload" id="fileUpload" multiple="false" sizeLimit="300000" fileUploadListener="#{articleBean.handleFileUpload}" allowTypes="*.xml;" 
										update="fileUploadForm" customUI="true" width="250px">
										<div class="fileUploadUI">
											<h:outputLink value="javascript:void(0)" onclick="fileUpload.upload();">#{bundle_admin['admin.article.articleBulkUpload.uploadFile']}</h:outputLink>
											<p:spacer width="20"/>
											<h:outputLink value="javascript:void(0)" onclick="fileUpload.clear();">#{bundle_admin['admin.article.articleBulkUpload.clearUploadFile']}</h:outputLink>
										</div>
									</p:fileUpload>
									<p:message id="fileUploadError" for="fileUpload" rendered="#{!articleBean.bulkUpload}"/>
						    		
						    		<p:commandButton id="articleBulkUploadBtn" ajax="true" action="#{articleBean.articleBulkUpload}" value="#{bundle_admin['admin.article.articleBulkUpload']}"
						    		 rendered="#{articleBean.bulkUpload}" update="fileUploadForm"/>
						    		<p:message id="fileUploadMsg" for="fileUpload" rendered="#{articleBean.bulkUpload}"/>
								</h:panelGrid>
							</div>
					    </h:form>
					</f:view>
				</ui:define>
			</ui:decorate>
		</ui:define>
</ui:composition>